package com.echo.im.common.result;

import lombok.Data;

/**
 *
 * @author echo
 * @date 2024-08-18
 */
@Data
public class Result<T> {

    private int code;

    private String message;

    private T data;

    private Result(ResultEnum resultEnum, T data) {
        this.code = resultEnum.getCode();
        this.message = resultEnum.getMessage();
        this.data = data;
    }

    private Result(Integer code, String message) {
        this.code = code;
        this.message =message;
    }

    public static <T> Result<T> success() {
        return new Result<>(ResultEnum.SUCCESS,null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(ResultEnum.SUCCESS, data);
    }

    public static <T> Result<T> fail(Integer code, String message) {
        return new Result<>(code,message);
    }

    public static <T> Result<T> fail(ResultEnum resultEnum) {
        return new Result<>(resultEnum, null);
    }

    public static <T> Result<T> error() {
        return new Result<>(ResultEnum.PROGRAM_ERROR,null);
    }
}
